#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int head;
    int tail;
    unsigned char * p_mem;
    int cur_num;
    int cap;
}queue_st;


int queue_init(queue_st * me, int cap)
{
    if(NULL == me || cap <= 0)
    {
        return -2;
    }
    
    me->cap = cap;
    me->head = 0;
    me->tail = 0;
    me->cur_num = 0;
    me->cap = cap;
    me->p_mem = malloc(cap);
    if(NULL == me->p_mem)
    {
        return -1;
    }

    return 0;
}

int queue_in(queue_st * me, uint8_t data)
{
    if(NULL == me)
    {
        return -2;
    }

    if(me->cur_num >= me->cap)
    {
        return -1;
    }

    me->p_mem[me->head] = data;
    me->head = (me->head + 1) % me->cap;
    me->cur_num++;
    return 0;
}

int queue_out(queue_st * me ,uint8_t * p_data)
{
    if(NULL == me || NULL == p_data)
    {
        return -2;
    }

    if(me->cur_num <= 0)
    {
        return -1;
    }

    * p_data = me->p_mem[me->tail];
    me->tail = (me->tail + 1) % me->cap;
    me->cur_num--;
    return 0;
}

int main(void)
{
	printf("hello\n");
	return 0;
}
